package com.zheng.current;

/**
 * @author: ztl
 * @date: 2025/06/18 23:00
 * @desc:
 */

import com.zheng.current.dto.Task;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 动态获取任务实现
 * @author wangmi
 */
public class FlightMultiChannelParallelQueryFactory {
    private FlightMultiChannelParallelQueryFactory() {
    }

    private static Map<Task, IFlightMultiTaskConformability> queryFactory = null;
    static {
        Map<String,IFlightMultiTaskConformability> map = SpringContextHolder.getApplicationContext().getBeansOfType(IFlightMultiTaskConformability.class);
        queryFactory = new ConcurrentHashMap<>();
        for (Map.Entry<String,IFlightMultiTaskConformability> entry : map.entrySet()) {
            queryFactory.put(entry.getValue().category(),entry.getValue());
        }
    }

    @SuppressWarnings("unchecked")
    public static <T extends IFlightMultiTaskConformability> T getTaskConsolidationManager(Task task) {
        if(task==null) {
            return null;
        }
        return (T)queryFactory.get(task);
    }

}
